package com.example.lotterysystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.lotterysystem.common.enums.ActivityUserStatusEnum;
import com.example.lotterysystem.dao.dataobject.ActivityUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityUserMapper extends BaseMapper<ActivityUser> {
    @Insert("<script> insert into activity_user (activity_id, user_id, user_name, status)" +
            " values <foreach collection = 'items' item = 'item' index = 'index' separator=','>" +
            " (#{item.activityId}, #{item.userId}, #{item.userName}, #{item.status})" +
            " </foreach>" + " </script>")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    Integer batchInsert(@Param("items") List<ActivityUser> activityUserList);

    @Update(" <script>" +
            " update activity_user set status = #{status} where activity_id = #{activityId} and " +
            " user_id in" +
            " <foreach collection='userIds' item='userId' open='(' separator=',' close=')' > " +
            " #{userId}" +
            " </foreach>" +
            " </script>")
    Integer updateUsersStatus(@Param("activityId") Long activityId, @Param("userIds") List<Long> userIds, @Param("status") String status);

}
